package com.rongc.client.freight;


import com.rongc.client.core.QuickApplication;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.base.model.BaseDic;
import com.rongc.client.freight.base.model.UserBean;

import cn.jpush.android.api.JPushInterface;

public class UniApplication extends QuickApplication {

    private UserBean userInfo;
    public static UniApplication getInstance() {
        return (UniApplication) QuickApplication.getInstance();
    }

    @Override
    public void onCreate() {
        super.onCreate();

        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        initData();
    }

    private void initData() {
        getUserInfo();
    }

    public UserBean getUserInfo() {
        if (userInfo == null) {
            userInfo = UserBean.load();
            if(userInfo == null) userInfo = new UserBean();
        }
        return userInfo;
    }

    public boolean hasLogin(){
        getUserInfo();
        if (userInfo == null){
            return false;
        } else if(StringUtils.isEmpty(userInfo.getUserId())){
            return false;
        }else {
            return true;
        }
    }

    public boolean hasType(){
        getUserInfo();
        if (userInfo == null){
            return false;
        } /*
        // TODO 验证是否有身份
        else if(StringUtils.isEmpty(userInfo.get)){
            return false;
        }*/else {
            return true;
        }
    }

    public String getType(){
        getUserInfo();
        if(BaseDic.IdentityType.DRIVING_TYPE.equals(userInfo.getType())){
            return BaseDic.IdentityType.DRIVING_TYPE;
        }else{
            return BaseDic.IdentityType.OWNER_TYPE;
        }
    }
}